package com.kgcx.opc.rabbit.receiver;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.bean.Message;
import com.kgcx.opc.service.AssignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 何凯
 * @version 0.1
 * @description
 * @time 2017/11/16 14:01
 * @since 0.1
 */
@Slf4j
@Component

public class ApiReceiver {
    @Autowired
    private AssignService assignService;

    @RabbitListener(queues = "kgcx.assign.api", errorHandler = "custRabbitListenerErrorHandler")
    public void processApi(String message) {
        try {
            Message messages = JSONObject.parseObject(message, Message.class);
            assignService.forwordApi(messages);
        } catch (Exception e) {
            log.error("MQ消费失败:", e.getMessage());
            e.printStackTrace();
        }

    }
}
